package cn.smile;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import java.io.File;

/**
 * Hello world!
 */
public class Excel {

    public static void main(String[] args) throws Exception {
        //这个Excel的文件
        File file = new File("C:\\Users\\86131\\Desktop\\" + System.currentTimeMillis() + ".xls");
        //创建Excel工作薄，所有操作围绕着该对象
        final WritableWorkbook workbook = Workbook.createWorkbook(file);
        //第一个sheet
        final WritableSheet sheet = workbook.createSheet("用户数据", 0);
        //最上面的标题
        final String[] titles = {"用户名", "年龄", "出生日期"};
        //标签
        Label label = null;
        //遍历所有标题
        for (int i = 0; i < titles.length; i++) {
            //参数1：第几列    参数2：第几行   参数3：插入的数据
            label = new Label(i, 0, titles[i]);
            //添加标签到Excel中去
            sheet.addCell(label);
        }
        for (int i = 1; i <= 100; i++) {
            label = new Label(0, i, "刘思晴" + i);
            sheet.addCell(label);
            label = new Label(1, i, "17");
            sheet.addCell(label);
            label = new Label(2, i, "2002-05-03");
            sheet.addCell(label);
        }
        //写入到Excel中
        workbook.write();
        workbook.close();
    }

}
